/* Testing the embargo card effect */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set TEST_OUTPUT to 0 to remove printfs from output
#define TEST_OUTPUT 0

int main() {
	int i;
	int seed = 100;
	int numPlayer = MAX_PLAYERS;
	//These just satisfy the card effect function call, but (perceivably) have no bearing on the card under test
	int choice2 = 0;
	int choice3 = 0;
	int *bonus = NULL;
	//End filler variables
	int choice1;
	int currentPlayer;
	int handPos;
	//From the example
	int k[10] = {adventurer, council_room, feast, gardens, mine, embargo, smithy, village, baron, great_hall};
	struct gameState G;
	struct gameState G_before;
	//Taken from the example testUpdateCoins.c, but still quite necessary.
	memset(&G, 23, sizeof(struct gameState));   			// clear the game state
    initializeGame(numPlayer, k, seed, &G); 			// beforeialize a new game
	memcpy(&G_before, &G, sizeof(struct gameState));		//Copy the beforeialized game state for future reference and state adjustment.
	//Set up the hand and player
	currentPlayer = 0;
	handPos = 0;
	//Insert the card in player 0's hand in position 0
	G.hand[currentPlayer][handPos] = embargo;
	
	//Need to check for all the possible choices, both good and bad.
	for (choice1 = 0; choice1 < (treasure_map + 1); ++choice1)
	{
		memcpy(&G, &G_before, sizeof(struct gameState));	 //Returning to the original state
		//Now play the card and make sure all the expected state changes have occurred
		i = cardEffect(embargo, choice1, choice2, choice3, &G, handPos, bonus);
		//cardEffect should return a -1 if the choice is not active, but still increment the coin count
		if (G.supplyCount[choice1] == -1)
		{
			assert(G.coins == G_before.coins + 2);
			assert(i == -1);
		} else {
		assert(G.coins == G_before.coins + 2);
		//The number of cards in the hand of the player should now be 1 less
		assert(G.handCount[currentPlayer] == (G_before.handCount[currentPlayer] - 1));
		
		//The number of embargo tokens for that choice should be incremented by one
		assert(G.embargoTokens[choice1] == G_before.embargoTokens[choice1] + 1);
		
		//The embargo card gets trashed not discarded, so in addition to checking the hand, we need to ensure the discardCount is kept the same.
		if (TEST_OUTPUT) printf("G.playedCardCount is %d\nG_before.playedCardCount is %d\n", G.playedCardCount, G_before.playedCardCount);
		assert(G.playedCardCount == G_before.playedCardCount);
		
		//Finally make sure card effect returns the correct value
		assert(i == 0);
		}
	}
	
	printf("Cardtest3: All Tests Passed!\n");
	return 0;
}
	